package jp.co.toshiba.ffsa.action.csas;

import javax.annotation.Resource;

import jp.co.toshiba.ffsa.action.common.CommonAction;
import jp.co.toshiba.ffsa.form.csas.Csas105Form;
import jp.co.toshiba.ffsa.service.common.ConstantValue;
import jp.co.toshiba.ffsa.service.csas.Csas105Service;

import org.seasar.struts.annotation.ActionForm;
import org.seasar.struts.annotation.Execute;
import org.seasar.struts.util.MessageResourcesUtil;

/**
 * 正式登録完了
 * @author npc
 */
public class Csas105Action extends CommonAction {

    /** ActionForm */
    @ActionForm
    @Resource
    protected Csas105Form csas105Form;

    /** メッセージ */
    public String dataMessage = "";

    /** 画面ID */
    private String screenID = "CSAS105";

    /**
     * 初期処理
     * @return 画面遷移先
     * @throws Exception
     */
    @Execute(validator = false, urlPattern = "/csas/csas105/{reg}")
    public String index() throws Exception {
        try {
            if(this.csas105Form.reg != null){
                // Serviceクラスを呼び出す
                Csas105Service service = new Csas105Service();
                service.setReg(this.csas105Form.reg);

                String urlcheck = service.urlCheck();

                // 正式登録完了の場合
                if( urlcheck.equals("1")){
                    dataMessage = MessageResourcesUtil.getMessage("csas105.902");
                }
                // 仮登録の場合
                else if( urlcheck.equals("2")){
                    dataMessage = MessageResourcesUtil.getMessage("csas105.002");
                    // 操作ログ記述
                    String result = ConstantValue.success;
                    this.entryOperationHistory(this.screenID, "submit", null, result, service.getUserID());
                }
                // 一致するデータが存在しない場合
                else if( urlcheck.equals("3")){
                    dataMessage = MessageResourcesUtil.getMessage("csas105.901");
                }
                // 仮登録の有効期限(24時間)が過ぎている場合
                else if( urlcheck.equals("4")){
                    dataMessage = MessageResourcesUtil.getMessage("csas105.903");
                }
            }else{
                dataMessage = MessageResourcesUtil.getMessage("csas105.901");
            }
        } catch (Exception e) {
            this.errorLogWriter(e, "index", this.screenID);
            throw e;
        }
        return "/csas/csas105.jsp";
    }
}